package com.baitengsoft.patentservicemonitor.job.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class CloudUtils {
    /**
     * @Author: KennyGu
     * @Date: 2018/1/11
     * @Description: 专利类型转换
     */
    public static Integer patentType(String fileType) {
        Integer patentype = 0;
        switch (fileType) {
            case "有权-审定授权":
                patentype = 1;
                break;
            case "无权-未缴年费":
                patentype = 2;
                break;
            case "审中-实质审查":
                patentype = 3;
                break;
            case "无权-视为撤回":
                patentype = 4;
                break;
            case "审中-公开发明":
                patentype = 5;
                break;
            case "无权-驳回":
                patentype = 6;
                break;
            case "无权-期满终止":
                patentype = 7;
                break;
            case "无权-避重放弃":
                patentype = 8;
                break;
            case "无权-视为放弃":
                patentype = 9;
                break;
            case "无权-主动撤回":
                patentype = 10;
                break;
            case "无权-主动放弃":
                patentype = 11;
                break;
            case "无权-全部无效":
                patentype = 12;
                break;
            case "无权-其他失效":
                patentype = 13;
                break;
            case "有权-部分有效":
                patentype = 14;
                break;
            case "无权-部分无效":
                patentype = 1150;
                break;
            default:
                patentype = 0;
                break;
        }
        return patentype;
    }


    public static Integer getPatentHubPatentType(String type) {
        Integer lawState = 0;
        switch (type) {
            case "有效专利":
                lawState = 1;
                break;
            case "失效专利":
                lawState = 2;
                break;
            case "实质审查":
                lawState = 3;
                break;
            case "公开":
                lawState = 5;
                break;
            case "无效专利":
                lawState = 12;
                break;
            default:
                lawState = 0;
                break;
        }
        return lawState;
    }

    /**
     * @Author: KennyGu
     * @Date: 2018/1/11
     * @Description: 申请人类型转换
     */
    public static Integer applyPersonType(String fileType) {
        Integer applypersontype = 0;
        final String t1 = "企业";
        final String t2 = "院校";
        final String t3 = "其他";
        final String t4 = "科研机构";
        final String t5 = "机关团体";
        final String t6 = "个人";
        switch (fileType) {
            case t1:
                applypersontype = 1;
                break;
            case t2:
                applypersontype = 2;
                break;
            case t3:
                applypersontype = 3;
                break;
            case t4:
                applypersontype = 4;
                break;
            case t5:
                applypersontype = 5;
                break;
            case t6:
                applypersontype = 6;
                break;
            default:
                applypersontype = 0;
                break;
        }
        return applypersontype;
    }

    /**
     * @Author: KennyGu
     * @Date: 2018/1/11
     * @Description: 获取文件类型
     */
    public static String contentType(String fileType) {
        fileType = fileType.toLowerCase();
        String contentType = "";
        switch (fileType) {
            case "bmp":
                contentType = "image/bmp";
                break;
            case "gif":
                contentType = "image/gif";
                break;
            case "png":
            case "jpeg":
            case "jpg":
                contentType = "image/jpeg";
                break;
            case "html":
                contentType = "text/html";
                break;
            case "txt":
                contentType = "text/plain";
                break;
            case "vsd":
                contentType = "application/vnd.visio";
                break;
            case "ppt":
            case "pptx":
                contentType = "application/vnd.ms-powerpoint";
                break;
            case "doc":
            case "docx":
                contentType = "application/msword";
                break;
            case "xml":
                contentType = "text/xml";
                break;
            case "mp4":
                contentType = "video/mp4";
                break;
            default:
                contentType = "application/octet-stream";
                break;
        }
        return contentType;
    }

    /**
     * @Author: KennyGu
     * @Date: 2018/1/11
     * @Description: 流转字符串
     */
    public static String convertStreamToString(InputStream is) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int i = -1;
        while ((i = is.read()) != -1) {
            baos.write(i);
        }
        return baos.toString();
    }
}
